﻿using System;

namespace AgFractal.Fractals
{
    public class PopcornJulia : AbstractFractal
    {
        public PopcornJulia()
        {
            ID = new Guid("71CCC252-EA38-4469-A5D3-F69DF0AA0925");
            Name = Description = "Popcorn julia";
            R1 = -2.25; I1 = 1.5; R2 = 2.25; I2 = -1.5;
        }

        protected override short Calculate(double r, double i, short MaxIteration)
        {
            short j; double x = r, y = i, h = 0.05, t;
            for (j = 0; j < MaxIteration; j++)
            {
                if (x * x + y * y > 4) break;
                t = x;
                x = x - h * Math.Sin(y + Math.Tan(3 * y));
                y = y - h * Math.Sin(t + Math.Tan(3 * t));
            }
            return j;
        }
    }
}